package com.fzrskj.cloud.free.core.opitimize.session;

import com.fzrskj.cloud.free.core.utils.ConfigPropUtils;

/**
 * SessionUtils.
 *
 * @author zj.
 *         Created on 2019/2/25 0025.
 */
public class SessionCoreUtils {
    private final static String DRIVER_SERVLET = "servlet";
    private final static String DRIVER_MYSQL = "mysql";
    private final static String DRIVER_REDIS = "redis";
    private static String driver;
    static {
        driver = ConfigPropUtils.getValue("optimize.session.driver");
    }

    /**
     * 设置 Session.
     * @param key session name.
     * @param value session value.
     */
    public static void set(String key, Object value) {
        set(key, value, 0);
    }

    /**
     * 设置 Session.
     * @param key session name.
     * @param value session value.
     * @param timeout timeout(unit: second).
     */
    public static void set(String key, Object value, Integer timeout) {
        if (null == driver || DRIVER_SERVLET.equals(driver)) {
            SessionServletUtils.set(key, value, timeout);
        } else if (DRIVER_MYSQL.equals(driver)) {

        } else if (DRIVER_REDIS.equals(driver)) {

        }
    }

    /**
     * 获取Session.
     * @param key session name.
     * @param <T> target class.
     * @return T.
     */
    public static <T> T get(String key) {
        if (null == driver || DRIVER_SERVLET.equals(driver)) {
            return SessionServletUtils.get(key);
        } else if (DRIVER_MYSQL.equals(driver)) {

        } else if (DRIVER_REDIS.equals(driver)) {

        }
        return null;
    }


}
